package com.hxzy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hxzy.entity.Orders;
import com.hxzy.vo.OrdersVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface OrdersMapper extends BaseMapper<Orders> {

    Orders selectByPrimaryKey(Long id);

    /**
     * 查询当年交易额
     * @param merchantId
     * @return
     */
    long fullYearTotalMoney(Long merchantId);

    /**
     * 查询当前年的呢的交易笔数
     * @param merchantId
     * @return
     */
    long fullYearTotalOrders(Long merchantId);

    /**
     * 未完成的订单数
     * @param merchantId
     * @return
     */
    long outstandingOrders(Long merchantId);

    /**
     * 查询用户最近一笔订单信息
     * @param userId
     * @return
     */
    OrdersVO lastOrder(Long userId);

    /**
     * 更新订单支付时间
     * @param orderNumber
     * @param payTime
     * @Param buyerAmount
     * @return
     */
    @Update(value = "update orders set pay_method=2,checkout_time=#{payTime},status=2,amount=#{buyerAmount} where number=#{orderNumber}")
    int updateAliPayPayStatus(@Param(value = "orderNumber") String orderNumber,@Param(value = "payTime") String payTime,@Param(value = "buyerAmount")String buyerAmount);
}